# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pygtk
pkgbase=mingw-w64-python2-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=2.24.0
pkgrel=7
pkgdesc="Python bindings for the GTK widget set (mingw-w64)"
arch=('any')
url="http://www.pygtk.org"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-python2-cairo"
         "${MINGW_PACKAGE_PREFIX}-python2-gobject2"
         "${MINGW_PACKAGE_PREFIX}-atk"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-gtk2"
         "${MINGW_PACKAGE_PREFIX}-libglade")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-numpy")
options=('staticlibs' 'strip')
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.bz2
        001-python27.patch
        002-no-undefined.patch
        003-python-m4.patch
        004-pygtk-demo.patch
        005-atk-glib-libs.patch)
sha256sums=('cd1c1ea265bd63ff669e92a2d3c2a88eb26bcd9e5363e0f82c896e649f206912'
            '39a30456cba055a452bb55c74ef1ff2f5f7bfaad22855b4dd569ab009b56b682'
            '365df388b238899d08acf1caf2ae4c1b1bb3b7a768aec3709b80aced155d226e'
            'fed9d666c0bd3baa0a361a7cc9af8303e811921ccab849e770ff38fc50092d76'
            '2430bc0f52f3ca0f76b51e0d959e223941ce7c8dec363f64fb65157180481ac9'
            'fb6db5409041099d6ef913dfcee3389e763605e28e345abeb7424f7d2f1a5302')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/001-python27.patch
  patch -p1 -i ${srcdir}/002-no-undefined.patch
  patch -p1 -i ${srcdir}/003-python-m4.patch
  patch -p1 -i ${srcdir}/004-pygtk-demo.patch
  patch -p1 -i ${srcdir}/005-atk-glib-libs.patch

  autoreconf -fi -I m4
  #WANT_AUTOMAKE=latest ./autogen.sh
}

build() {
  rm -rf python2-build
  mkdir python2-build
  #cp -r ${_realname}-${pkgver} ${builddir}
  pushd python2-build > /dev/null
    PYTHON=${MINGW_PREFIX}/bin/python2 \
    ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}
    make VERBOSE=1
  popd > /dev/null
}

package() {
  cd python2-build
  make DESTDIR="${pkgdir}" install
  install -m644 ${srcdir}/${_realname}-${pkgver}/gtk/gtk-extrafuncs.defs "${pkgdir}${MINGW_PREFIX}/share/pygtk/2.0/defs/"
  sed -i -e 's#env python$#env python2#' "${pkgdir}${MINGW_PREFIX}"/lib/pygtk/2.0/{,demos/}*.py
}
